﻿' Licensed under GNU General Public License version 2 (GPLv2) 
' Copyright (C) 1989, 1991 Free Software Foundation, Inc.
'
' Everyone is permitted to copy and distribute verbatim copies
' of this license document, but changing it is not allowed.

''' <summary>
''' NumberList Class.
''' </summary>
''' <remarks></remarks>
Public Class NumberList
    Implements IDisposable

#Region "Member variables"
    Private _list As List(Of Integer) = New List(Of Integer)
    Private _minimum As Integer = -1
    Private _maximum As Integer = -1
    Private _disposedValue As Boolean = False
#End Region

#Region "Constructor"
    ''' <summary>
    ''' Returns a new instance of the NumberList class.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
    End Sub
#End Region

#Region "Public Properties"
    ''' <summary>
    ''' Gets the lowest number from the number collection.
    ''' </summary>
    ''' <value>Integer.</value>
    ''' <returns>Lowest number in range.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Minimum() As Integer
        Get
            Return _minimum
        End Get
    End Property

    ''' <summary>
    ''' Gets the largest number from the number collection.
    ''' </summary>
    ''' <value>Integer.</value>
    ''' <returns>Highest number in range.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Maximum() As Integer
        Get
            Return _maximum
        End Get
    End Property
#End Region

#Region "Public methods"
    ''' <summary>
    ''' Returns the average from all numbers in the range.
    ''' </summary>
    ''' <returns>Integer.</returns>
    ''' <remarks></remarks>
    Public Function Average() As Integer
        Dim numbers As Integer = 0

        For Each num As Integer In _list
            numbers += num
        Next

        Return numbers / _list.Count
    End Function

    ''' <summary>
    ''' Adds a number to the list.
    ''' </summary>
    ''' <param name="num">Integer to add.</param>
    ''' <remarks></remarks>
    Public Sub Add(ByVal num As Integer)
        _list.Add(num)

        If num > _maximum OrElse (_maximum = -1) Then _maximum = num
        If num < _minimum OrElse (_minimum = -1) Then _minimum = num
    End Sub
#End Region

#Region "Disposal methods"
    ''' <summary>
    ''' IDisposable implementation.
    ''' </summary>
    ''' <param name="disposing"></param>
    ''' <remarks></remarks>
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me._disposedValue Then
            If disposing Then
                _list.Clear()
                _list = Nothing
            End If
        End If
        Me._disposedValue = True
    End Sub
#End Region

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class
